Skip to content

D0.3 WireSweep DTOs + grid enumerator (Phase 0 surface complete, 71/71 tests)#232

Merged
AdaWorldAPI merged 1 commit into
mainfrom
claude/teleport-session-setup-wMZfb
Apr 20, 2026
Merged

D0.3 WireSweep DTOs + grid enumerator (Phase 0 surface complete, 71/71 tests)#232
AdaWorldAPI merged 1 commit into
mainfrom
claude/teleport-session-setup-wMZfb

Conversation

@AdaWorldAPI

Copy link
Copy Markdown
Owner

Summary

Last Phase 0 Wire-surface deliverable from codec-sweep-via-lab-infra-v1. Ships the DTOs + the grid enumerator; streaming handler + Lance writer defer to Phase 3 D3.1.

71/71 cognitive-shader-driver --features serve tests pass (+5 new).

What landed

WireMeasure enum (5 variants, snake_case serde)

reconstruction_error_held_out / reconstruction_icc_held_out / token_agreement_top1 / token_agreement_top5 / per_layer_mse.

WireSweepGrid — the Cartesian-product input surface

Every axis is a Vec<T> with sensible default (one element → cardinality 1). Axes:

pub struct WireSweepGrid {
    pub subspaces: Vec<u32>,          // default [6]
    pub centroids: Vec<u32>,          // default [256]
    pub residual_depths: Vec<u8>,     // default [0]
    pub rotations: Vec<WireRotation>, // default [Identity]
    pub distances: Vec<WireDistance>, // default [AdcU8]
    pub lane_widths: Vec<WireLaneWidth>, // default [F32x16]
    pub residual_centroids: u32,
    pub calibration_rows: u32,
    pub measurement_rows: u32,
    pub seed: u64,
}

impl WireSweepGrid {
    pub fn cardinality(&self) -> usize { /* product of axis lengths */ }
    pub fn enumerate(&self) -> Vec<WireCodecParams> { /* full Cartesian */ }
}

Example: 1 × 3 × 3 × 2 × 1 × 2 = 36 candidates for the plan's Appendix A §30 sweep.

WireSweepRequest + WireSweepResult + WireSweepResponse

Request carries tensor_path + grid + measure set + optional log_to_lance Lance fragment path + label. Each result carries the candidate + kernel_hash (the CodecParams::kernel_signature() of the executed kernel) + optional calibrate / token_agreement payloads + stub flag (D0.2 pattern — machine-checkable Phase-0-honesty).

The key insight (landed as epiphany)

The sweep grid IS the JIT cache warmer. Each unique tuple (subspaces, centroids, residual_depth, rotation_kind, distance, lane_width) maps to exactly one kernel_signature(). First traversal compiles N kernels; every subsequent sweep with overlapping tuples hits cache at ~0 ms compile cost. The grid axis and the cache signature are the same object viewed from two sides.

The 54-candidate Appendix A §30 sweep: ~800 ms one-time compile, free after. That's the operational loop D0.1–D0.7 buys.

Phase 0 state after merge

D-id Deliverable Status
D0.1 WireCalibrate + WireTensorView ✅ Shipped (#227)
D0.2 WireTokenAgreement stub ✅ Shipped (#231)
D0.3 WireSweep DTOs + grid ✅ This PR
D0.4 Surface freeze (rebuild gate) ✅ Fires on merge
D0.5 auto_detect ✅ Shipped (#231)
D0.6 CodecParamsBuilder ✅ Shipped (#225)
D0.7 Precision-ladder validation ✅ Shipped (#225)

After this PR merges, Phase 0 closes. Phase 1 (JIT kernels) begins next — D1.1 CodecKernelCache via JitCompiler compiles kernels per kernel_signature(); D1.2 rotation primitives; D1.3 residual PQ via JIT composition.

Board hygiene (same commit per Mandatory rule)

  • STATUS_BOARD.md: D0.3 Queued → In PR; D0.4 Queued → Ready.
  • EPIPHANIES.md PREPEND: "D0.3 sweep grid IS the JIT cache warmer".

Test Plan

  • cargo test --manifest-path crates/cognitive-shader-driver/Cargo.toml --features serve — 71/71 pass (+5 new)
  • cargo test -p lance-graph-contract --lib — 147/147 pass (unchanged)
  • cargo test --manifest-path crates/jc/Cargo.toml — 6/6 pass (JC substrate proof unchanged)
  • Rules A-F honored: D + E + F (DTO-only; cache signature returned per result)
  • Board-hygiene rule: STATUS_BOARD + EPIPHANIES in same commit

https://claude.ai/code/session_01SbYsmmbPf9YQuYbHZN52Zh

Last Phase 0 Wire-surface deliverable from codec-sweep-via-lab-infra-v1.
71/71 cognitive-shader-driver tests pass under --features serve
(+5 new D0.3 tests).

DTOs (~250 LOC in wire.rs):
  WireMeasure enum:
    ReconstructionErrorHeldOut / ReconstructionIccHeldOut /
    TokenAgreementTop1 / TokenAgreementTop5 / PerLayerMse
    (serde: lowercase snake_case)

  WireSweepGrid:
    subspaces / centroids / residual_depths / rotations /
    distances / lane_widths — each a Vec<T> with sensible defaults
    (defaults produce cardinality 1 for minimal payloads)
    + residual_centroids / calibration_rows / measurement_rows / seed
    Methods:
      - cardinality() -> usize — product of axis lengths
      - enumerate() -> Vec<WireCodecParams> — full Cartesian product

  WireSweepRequest:
    tensor_path / grid / measure (default: ICC + top-1) /
    log_to_lance (optional Lance fragment path) / label

  WireSweepResult (one per grid point):
    grid_index / candidate / kernel_hash (CodecParams::kernel_signature) /
    calibrate (Option<WireCalibrateResponse>) /
    token_agreement (Option<WireTokenAgreementResult>) /
    stub flag (mirrors WireTokenAgreementResult.stub)

  WireSweepResponse (for non-streaming batch clients):
    label / cardinality / results / elapsed_ms / lance_fragment_path

Streaming handler (SSE) + Lance writer deferred to Phase 3 D3.1.
Phase 0 ships the SURFACE; Phase 3 lands the execution.

Tests (5 new):
  - sweep_grid_cardinality_is_product_of_axes (1×3×3×2×1×2 = 36)
  - sweep_grid_enumerate_produces_all_unique_signatures
    (4 distinct kernel signatures from 4 distinct IR-shaping tuples)
  - sweep_grid_defaults_produce_single_candidate
    (empty JSON {} → cardinality 1, single default WireCodecParams)
  - sweep_request_round_trips_json (full payload with all fields)
  - sweep_measure_serializes_snake_case (serde enum format)

Board hygiene (CLAUDE.md Mandatory rule):
  STATUS_BOARD.md:
    D0.3 Queued → In PR
    D0.4 Queued → Ready (surface freeze fires on merge)

  EPIPHANIES.md PREPEND:
    "D0.3 sweep grid IS the JIT cache warmer" —
    the grid and the cache signature are the same object viewed
    from two sides. Each unique (subspaces, centroids,
    residual_depth, rotation_kind, distance, lane_width) tuple maps
    to exactly one kernel_signature(). First traversal compiles N
    kernels; every subsequent sweep with overlapping tuples hits
    cache at ~0 ms. 54-candidate Appendix A §30 sweep: ~800 ms
    one-time compile, free after.

Phase 0 state after this PR (all 7 D0.x deliverables):
  ✅ D0.1 WireCalibrate + WireTensorView (PR #227)
  ✅ D0.2 WireTokenAgreement stub (PR #231)
  ✅ D0.3 WireSweep DTOs + grid (this PR)
  ⏳ D0.4 surface freeze (fires on merge)
  ✅ D0.5 auto_detect (PR #231)
  ✅ D0.6 CodecParamsBuilder (PR #225)
  ✅ D0.7 precision-ladder validation (PR #225)

Rules honored (every Wire DTO in this PR):
  Rule D — JSON/YAML/REST only, never in-Rust construction at ingress
  Rule E — Wire surface IS SIMD surface (lane_widths axis explicit,
           kernel_hash returned per result)
  Rule F — serde mirrors at ingress only; enumerate() returns plain
           Rust objects that never re-serialize until egress

After this PR merges: D0.4 surface freeze → Phase 1 (JIT kernels) begins.

https://claude.ai/code/session_01SbYsmmbPf9YQuYbHZN52Zh
@AdaWorldAPI AdaWorldAPI merged commit b06f9f9 into main Apr 20, 2026
0 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants